/* $Id$ */
package org.crazydays.gameplan;


import org.junit.*;
import static org.junit.Assert.*;

import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;

import org.crazydays.gameplan.db.Database;

/**
 * ActionsUnitTest
 */
public class ActionsUnitTest
{
    /**
     * Test initialize().
     */
    @Test
    public void testInitialize()
    {
        // mocks
        Controller controller = createMock(Controller.class);

        // replay
        replay(controller);

        // setup
        Actions actions = new Actions(controller);

        // test
        actions.initialize();

        // verify
        verify(controller);

        assertNotNull("createDatabase", actions.getCreateDatabase());
        assertTrue("newDatabase.enabled", actions.getCreateDatabase()
            .isEnabled());
        assertNotNull("openDatabase", actions.getOpenDatabase());
        assertTrue("openDatabase.enabled", actions.getOpenDatabase()
            .isEnabled());
        assertNotNull("openDatabase", actions.getOpenDatabase());
        assertTrue("openDatabase.enabled", actions.getOpenDatabase()
            .isEnabled());
        assertNotNull("closeDatabase", actions.getCloseDatabase());
        assertFalse("closeDatabase.enabled", actions.getCloseDatabase()
            .isEnabled());
        assertNotNull("saveDatabase", actions.getSaveDatabase());
        assertFalse("saveDatabase.enabled", actions.getSaveDatabase()
            .isEnabled());
        assertNotNull("saveDatabaseAs", actions.getSaveDatabaseAs());
        assertFalse("saveDatabaseAs.enabled", actions.getSaveDatabaseAs()
            .isEnabled());
        assertNotNull("createMapDialog", actions.getCreateMapDialog());
        assertFalse("createMapDialog", actions.getCreateMapDialog().isEnabled());
        assertNotNull("gridToggle", actions.getToggleGrid());
        assertFalse("gridToggle.enabled", actions.getToggleGrid().isEnabled());
        assertNotNull("about", actions.getAbout());
        assertTrue("about.enabled", actions.getAbout().isEnabled());
        assertNotNull("exit", actions.getExit());
        assertTrue("exit.enabled", actions.getExit().isEnabled());
    }

    /**
     * Test opened(Database).
     */
    @Test
    public void testOpened()
    {
        // mocks
        Controller controller = createMock(Controller.class);
        Database database = createMock(Database.class);

        // replay
        replay(controller, database);

        // setup
        Actions actions = new Actions(controller);
        actions.initialize();

        // test
        actions.opened(database);

        // verify
        verify(controller, database);

        assertEquals("createDatabase", false, actions.createDatabase
            .isEnabled());
        assertEquals("openDatabase", false, actions.openDatabase.isEnabled());
        assertEquals("saveDatabase", true, actions.saveDatabase.isEnabled());
        assertEquals("saveDatabaseAs", true, actions.saveDatabaseAs.isEnabled());
        assertEquals("createMapDialog", true, actions.createMapDialog
            .isEnabled());
        assertEquals("closeDatabase", true, actions.closeDatabase.isEnabled());
    }

    /**
     * Test closed(Database).
     */
    @Test
    public void testClosed()
    {
        // mocks
        Controller controller = createMock(Controller.class);
        Database database = createMock(Database.class);

        // replay
        replay(controller, database);

        // setup
        Actions actions = new Actions(controller);
        actions.initialize();

        // test
        actions.closed(database);

        // verify
        verify(controller, database);

        assertEquals("createDatabase", true, actions.createDatabase.isEnabled());
        assertEquals("openDatabase", true, actions.openDatabase.isEnabled());
        assertEquals("saveDatabase", false, actions.saveDatabase.isEnabled());
        assertEquals("saveDatabaseAs", false, actions.saveDatabaseAs
            .isEnabled());
        assertEquals("createMapDialog", false, actions.createMapDialog
            .isEnabled());
        assertEquals("closeDatabase", false, actions.closeDatabase.isEnabled());
    }

    /**
     * Test enableMapOptions().
     */
    @Test
    public void testEnableMapOptions()
    {
        // mocks
        Controller controller = createMock(Controller.class);
        Database database = createMock(Database.class);

        // replay
        replay(controller, database);

        // setup
        Actions actions = new Actions(controller);
        actions.initialize();

        // test
        actions.enableMapOptions();

        // verify
        verify(controller, database);

        assertEquals("gridToggle", true, actions.toggleGrid.isEnabled());
    }

    /**
     * Test disableMapOptions().
     */
    @Test
    public void testDisableMapOptions()
    {
        // mocks
        Controller controller = createMock(Controller.class);
        Database database = createMock(Database.class);

        // replay
        replay(controller, database);

        // setup
        Actions actions = new Actions(controller);
        actions.initialize();

        // test
        actions.disableMapOptions();

        // verify
        verify(controller, database);

        assertEquals("gridToggle", false, actions.toggleGrid.isEnabled());
    }
}
